home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / CIncludes / fp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-12  |  28.9 KB  |  780 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        fp.h
  3.  
  4.      Contains:    FPCE Floating-Point Definitions and Declarations.
  5.  
  6.      Version:    Technology:    MathLib v2
  7.                  Release:    Universal Interfaces 3.0.1
  8.  
  9.      Copyright:    © 1987-1997 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __FP__
  19. #define __FP__
  20.  
  21. #ifndef __CONDITIONALMACROS__
  22. #include <ConditionalMacros.h>
  23. #endif
  24.  
  25. #if TARGET_OS_MAC
  26. #ifndef __TYPES__
  27. #include <Types.h>
  28. #endif
  29. #endif
  30. /********************************************************************************
  31. *                                                                               *
  32. *    A collection of numerical functions designed to facilitate a wide          *
  33. *    range of numerical programming as required by C9X.                         *
  34. *                                                                               *
  35. *    The <fp.h> declares many functions in support of numerical programming.    *
  36. *    It provides a superset of <math.h> and <SANE.h> functions.  Some           *
  37. *    functionality previously found in <SANE.h> and not in the FPCE <fp.h>      *
  38. *    can be found in this <fp.h> under the heading "__NOEXTENSIONS__".          *
  39. *                                                                               *
  40. *    All of these functions are IEEE 754 aware and treat exceptions, NaNs,      *
  41. *    positive and negative zero and infinity consistent with the floating-      *
  42. *    point standard.                                                            *
  43. *                                                                               *
  44. ********************************************************************************/
  45.  
  46.  
  47.  
  48. #if PRAGMA_ONCE
  49. #pragma once
  50. #endif
  51.  
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55.  
  56. #if PRAGMA_IMPORT
  57. #pragma import on
  58. #endif
  59.  
  60. #if PRAGMA_STRUCT_ALIGN
  61.     #pragma options align=mac68k
  62. #elif PRAGMA_STRUCT_PACKPUSH
  63.     #pragma pack(push, 2)
  64. #elif PRAGMA_STRUCT_PACK
  65.     #pragma pack(2)
  66. #endif
  67.  
  68. /********************************************************************************
  69. *                                                                               *
  70. *                            Efficient types                                    *
  71. *                                                                               *
  72. *    float_t         Most efficient type at least as wide as float              *
  73. *    double_t        Most efficient type at least as wide as double             *
  74. *                                                                               *
  75. *      CPU            float_t(bits)                double_t(bits)               *
  76. *    --------        -----------------            -----------------             *
  77. *    PowerPC          float(32)                    double(64)                   *
  78. *    68K              long double(80/96)           long double(80/96)           *
  79. *                                                                               *
  80. ********************************************************************************/
  81. #if TARGET_CPU_PPC
  82. typedef float                             float_t;
  83. typedef double                             double_t;
  84. #elif TARGET_CPU_68K
  85. typedef long double                     float_t;
  86. typedef long double                     double_t;
  87. #else
  88. #error unsupported CPU
  89. #endif  /* TARGET_CPU_68K */
  90.  
  91.  
  92. /********************************************************************************
  93. *                                                                               *
  94. *                              Define some constants.                           *
  95. *                                                                               *
  96. *    HUGE_VAL            IEEE 754 value of infinity.                            *
  97. *    INFINITY            IEEE 754 value of infinity.                            *
  98. *    NAN                 A generic NaN (Not A Number).                          *
  99. *    DECIMAL_DIG         Satisfies the constraint that the conversion from      *
  100. *                        double to decimal and back is the identity function.   *
  101. *                                                                               *
  102. ********************************************************************************/
  103.  
  104. #define      HUGE_VAL                  __inf()
  105. #define      INFINITY                  __inf()
  106. #define      NAN                       nan("255")
  107.  
  108. #if TARGET_CPU_PPC
  109.     #define      DECIMAL_DIG              17 /* does not exist for double-double */
  110. #elif TARGET_CPU_68K
  111.     #define      DECIMAL_DIG              21
  112. #endif      
  113.  
  114.  
  115. /********************************************************************************
  116. *                                                                               *
  117. *                            Trigonometric functions                            *
  118. *                                                                               *
  119. *   acos        result is in [0,pi].                                            *
  120. *   asin        result is in [-pi/2,pi/2].                                      *
  121. *   atan        result is in [-pi/2,pi/2].                                      *
  122. *   atan2       Computes the arc tangent of y/x in [-pi,pi] using the sign of   *
  123. *               both arguments to determine the quadrant of the computed value. *
  124. *                                                                               *
  125. ********************************************************************************/
  126. EXTERN_API_C( double_t ) cos(double_t x);
  127.  
  128. EXTERN_API_C( double_t ) sin(double_t x);
  129.  
  130. EXTERN_API_C( double_t ) tan(double_t x);
  131.  
  132. EXTERN_API_C( double_t ) acos(double_t x);
  133.  
  134. EXTERN_API_C( double_t ) asin(double_t x);
  135.  
  136. EXTERN_API_C( double_t ) atan(double_t x);
  137.  
  138. EXTERN_API_C( double_t ) atan2(double_t y, double_t x);
  139.  
  140.  
  141.  
  142. /********************************************************************************
  143. *                                                                                *
  144. *                              Hyperbolic functions                             *
  145. *                                                                                *
  146. ********************************************************************************/
  147. EXTERN_API_C( double_t ) cosh(double_t x);
  148.  
  149. EXTERN_API_C( double_t ) sinh(double_t x);
  150.  
  151. EXTERN_API_C( double_t ) tanh(double_t x);
  152.  
  153. EXTERN_API_C( double_t ) acosh(double_t x);
  154.  
  155. EXTERN_API_C( double_t ) asinh(double_t x);
  156.  
  157. EXTERN_API_C( double_t ) atanh(double_t x);
  158.  
  159.  
  160.  
  161. /********************************************************************************
  162. *                                                                                *
  163. *                              Exponential functions                               *
  164. *                                                                                *
  165. *    expm1        expm1(x) = exp(x) - 1.  But, for small enough arguments,          *
  166. *                expm1(x) is expected to be more accurate than exp(x) - 1.        *
  167. *    frexp        Breaks a floating-point number into a normalized fraction       *
  168. *                and an integral power of 2.  It stores the integer in the       *
  169. *                object pointed by *exponent.                                    *
  170. *    ldexp        Multiplies a floating-point    number by an integer power of 2.    *
  171. *    log1p        log1p = log(1 + x). But, for small enough arguments,              *
  172. *                 log1p is expected to be more accurate than log(1 + x).          *
  173. *    logb        Extracts the exponent of its argument, as a signed integral        *
  174. *                  value. A subnormal argument is treated as though it were first    *
  175. *                  normalized. Thus:                                                *
  176. *                                     1   <=   x * 2^(-logb(x))   <   2             *
  177. *    modf        Returns fractional part of x as function result and returns     *
  178. *                integral part of x via iptr. Note C9X uses double not double_t.    *
  179. *    scalb        Computes x * 2^n efficently.  This is not normally done by        *
  180. *                  computing 2^n explicitly.                                         *
  181. *                                                                                *
  182. ********************************************************************************/
  183. EXTERN_API_C( double_t ) exp(double_t x);
  184.  
  185. EXTERN_API_C( double_t ) expm1(double_t x);
  186.  
  187. EXTERN_API_C( double_t ) exp2(double_t x);
  188.  
  189. EXTERN_API_C( double_t ) frexp(double_t x, int *exponent);
  190.  
  191. EXTERN_API_C( double_t ) ldexp(double_t x, int n);
  192.  
  193. EXTERN_API_C( double_t ) log(double_t x);
  194.  
  195. EXTERN_API_C( double_t ) log2(double_t x);
  196.  
  197. EXTERN_API_C( double_t ) log1p(double_t x);
  198.  
  199. EXTERN_API_C( double_t ) log10(double_t x);
  200.  
  201. EXTERN_API_C( double_t ) logb(double_t x);
  202.  
  203. EXTERN_API_C( long double ) modfl(long double x, long double *iptrl);
  204.  
  205. EXTERN_API_C( double_t ) modf(double_t x, double_t *iptr);
  206.  
  207. EXTERN_API_C( float ) modff(float x, float *iptrf);
  208.  
  209. EXTERN_API_C( double_t ) scalb(double_t x, long n);
  210.  
  211.  
  212.  
  213. /********************************************************************************
  214. *                                                                                *
  215. *                     Power and absolute value functions                          *
  216. *                                                                                *
  217. *    hypot        Computes the square root of the sum of the squares of its        *
  218. *                  arguments, without undue overflow or underflow.                 *
  219. *    pow            Returns x raised to the power of y.  Result is more accurate    *
  220. *                than using exp(log(x)*y).                                        *
  221. *                                                                                *
  222. ********************************************************************************/
  223. EXTERN_API_C( double_t ) fabs(double_t x);
  224.  
  225. EXTERN_API_C( double_t ) hypot(double_t x, double_t y);
  226.  
  227. EXTERN_API_C( double_t ) pow(double_t x, double_t y);
  228.  
  229. EXTERN_API_C( double_t ) sqrt(double_t x);
  230.  
  231.  
  232.  
  233. /********************************************************************************
  234. *                                                                                 *
  235. *                        Gamma and Error functions                               *
  236. *                                                                                 *
  237. *     erf            The error function.                                             *
  238. *     erfc        Complementary error function.                                      *
  239. *     gamma        The gamma function.                                                *
  240. *     lgamma        Computes the base-e logarithm of the absolute value of            *
  241. *                 gamma of its argument x, for x > 0.                                *
  242. *                                                                                 *
  243. ********************************************************************************/
  244. EXTERN_API_C( double_t ) erf(double_t x);
  245.  
  246. EXTERN_API_C( double_t ) erfc(double_t x);
  247.  
  248. EXTERN_API_C( double_t ) gamma(double_t x);
  249.  
  250. EXTERN_API_C( double_t ) lgamma(double_t x);
  251.  
  252.  
  253.  
  254. /********************************************************************************
  255. *                                                                                 *
  256. *                        Nearest integer functions                                 *
  257. *                                                                                 *
  258. *     rint        Rounds its argument to an integral value in floating point         *
  259. *                  format, honoring the current rounding direction.                   *
  260. *                                                                                 *
  261. *     nearbyint    Differs from rint only in that it does not raise the inexact    *
  262. *               exception. It is the nearbyint function recommended by the        *
  263. *                  IEEE floating-point standard 854.                                  *
  264. *                                                                                 *
  265. *     rinttol        Rounds its argument to the nearest long int using the current     *
  266. *                  rounding direction.  NOTE: if the rounded value is outside        *
  267. *                the range of long int, then the result is undefined.              *
  268. *                                                                                  *
  269. *     round        Rounds the argument to the nearest integral value in floating     *
  270. *                  point format similar to the Fortran "anint" function. That is:  *
  271. *                  add half to the magnitude and chop.                             *
  272. *                                                                                 *
  273. *     roundtol    Similar to the Fortran function nint or to the Pascal round.    *
  274. *                 NOTE: if the rounded value is outside the range of long int,    *
  275. *                  then the result is undefined.                                      *
  276. *                                                                                 *
  277. *     trunc        Computes the integral value, in floating format, nearest to        *
  278. *                 but no larger in magnitude than its argument.      NOTE: on 68K    *
  279. *                compilers when using -elems881, trunc must return an int        *
  280. *                                                                                 *
  281. ********************************************************************************/
  282. EXTERN_API_C( double_t ) ceil(double_t x);
  283.  
  284. EXTERN_API_C( double_t ) floor(double_t x);
  285.  
  286. EXTERN_API_C( double_t ) rint(double_t x);
  287.  
  288. EXTERN_API_C( double_t ) nearbyint(double_t x);
  289.  
  290. EXTERN_API_C( long ) rinttol(double_t x);
  291.  
  292. EXTERN_API_C( double_t ) round(double_t x);
  293.  
  294. EXTERN_API_C( long ) roundtol(double_t round);
  295.  
  296. #if TARGET_CPU_68K
  297. EXTERN_API_C( int ) trunc(double_t x);
  298.  
  299. #else
  300. EXTERN_API_C( double_t ) trunc(double_t x);
  301.  
  302. #endif  /* TARGET_CPU_68K */
  303.  
  304.  
  305. /********************************************************************************
  306. *                                                                                 *
  307. *                            Remainder functions                                   *
  308. *                                                                                 *
  309. *     remainder        IEEE 754 floating point standard for remainder.                *
  310. *     remquo            SANE remainder.  It stores into 'quotient' the 7 low-order    *
  311. *                    bits of the integer quotient x/y, such that:                *
  312. *                        -127 <= quotient <= 127.                                 *
  313. *                                                                                 *
  314. ********************************************************************************/
  315. EXTERN_API_C( double_t ) fmod(double_t x, double_t y);
  316.  
  317. EXTERN_API_C( double_t ) remainder(double_t x, double_t y);
  318.  
  319. EXTERN_API_C( double_t ) remquo(double_t x, double_t y, int *quo);
  320.  
  321.  
  322.  
  323. /********************************************************************************
  324. *                                                                                 *
  325. *                             Auxiliary functions                               *
  326. *                                                                                 *
  327. *     copysign        Produces a value with the magnitude of its first argument    *
  328. *                      and sign of its second argument.  NOTE: the order of the     *
  329. *                      arguments matches the recommendation of the IEEE 754         *
  330. *                    floating point standard,  which is opposite from the SANE    *
  331. *                    copysign function.                                             *
  332. *                                                                                 *
  333. *     nan                The call 'nan("n-char-sequence")' returns a quiet NaN         *
  334. *                      with content indicated through tagp in the selected         *
  335. *                    data type format.                                              *
  336. *                                                                                *
  337. *     nextafter        Computes the next representable value after 'x' in the         *
  338. *                    direction of 'y'.  if x == y, then y is returned.            *
  339. *                                                                                 *
  340. ********************************************************************************/
  341. EXTERN_API_C( double_t ) copysign(double_t x, double_t y);
  342.  
  343. EXTERN_API_C( long double ) nanl(const char *tagp);
  344.  
  345. EXTERN_API_C( double ) nan(const char *tagp);
  346.  
  347. EXTERN_API_C( float ) nanf(const char *tagp);
  348.  
  349. EXTERN_API_C( long double ) nextafterl(long double x, long double y);
  350.  
  351. EXTERN_API_C( double ) nextafterd(double x, double y);
  352.  
  353. EXTERN_API_C( float ) nextafterf(float x, float y);
  354.  
  355.  
  356.  
  357. /********************************************************************************
  358. *                                                                                 *
  359. *                              Inquiry macros                                   *
  360. *                                                                                 *
  361. *     fpclassify        Returns one of the FP_≈ values.                                *
  362. *     isnormal        Non-zero if and only if the argument x is normalized.          *
  363. *     isfinite        Non-zero if and only if the argument x is finite.             *
  364. *     isnan            Non-zero if and only if the argument x is a NaN.              *
  365. *     signbit            Non-zero if and only if the sign of the argument x is        *
  366. *                      negative.  This includes, NaNs, infinities and zeros.         *
  367. *                                                                                 *
  368. ********************************************************************************/
  369.  
  370. enum {
  371.     FP_SNAN                        = 0,                            /*      signaling NaN                         */
  372.     FP_QNAN                        = 1,                            /*      quiet NaN                             */
  373.     FP_INFINITE                    = 2,                            /*      + or - infinity                       */
  374.     FP_ZERO                        = 3,                            /*      + or - zero                           */
  375.     FP_NORMAL                    = 4,                            /*      all normal numbers                    */
  376.     FP_SUBNORMAL                = 5                                /*      denormal numbers                      */
  377. };
  378.  
  379. #define      fpclassify(x)    ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  380.                               __fpclassify  ( x ) :                            \
  381.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  382.                               __fpclassifyd ( x ) :                            \
  383.                               __fpclassifyf ( x ) )
  384. #define      isnormal(x)      ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  385.                               __isnormal ( x ) :                               \
  386.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  387.                               __isnormald ( x ) :                              \
  388.                               __isnormalf ( x ) )
  389. #define      isfinite(x)      ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  390.                               __isfinite ( x ) :                               \
  391.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  392.                               __isfinited ( x ) :                              \
  393.                               __isfinitef ( x ) )
  394. #define      isnan(x)         ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  395.                               __isnan ( x ) :                                  \
  396.                               ( sizeof ( x ) == sizeof(double) ) ?             \
  397.                               __isnand ( x ) :                                 \
  398.                               __isnanf ( x ) )
  399. #define      signbit(x)       ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  400.                               __signbit ( x ) :                                \
  401.                               ( sizeof ( x ) == sizeof(double) ) ?             \
  402.                               __signbitd ( x ) :                               \
  403.                               __signbitf ( x ) )
  404. EXTERN_API_C( long ) __fpclassify(long double x);
  405.  
  406. EXTERN_API_C( long ) __fpclassifyd(double x);
  407.  
  408. EXTERN_API_C( long ) __fpclassifyf(float x);
  409.  
  410. EXTERN_API_C( long ) __isnormal(long double x);
  411.  
  412. EXTERN_API_C( long ) __isnormald(double x);
  413.  
  414. EXTERN_API_C( long ) __isnormalf(float x);
  415.  
  416. EXTERN_API_C( long ) __isfinite(long double x);
  417.  
  418. EXTERN_API_C( long ) __isfinited(double x);
  419.  
  420. EXTERN_API_C( long ) __isfinitef(float x);
  421.  
  422. EXTERN_API_C( long ) __isnan(long double x);
  423.  
  424. EXTERN_API_C( long ) __isnand(double x);
  425.  
  426. EXTERN_API_C( long ) __isnanf(float x);
  427.  
  428. EXTERN_API_C( long ) __signbit(long double x);
  429.  
  430. EXTERN_API_C( long ) __signbitd(double x);
  431.  
  432. EXTERN_API_C( long ) __signbitf(float x);
  433.  
  434. EXTERN_API_C( double_t ) __inf(void );
  435.  
  436.  
  437.  
  438. /********************************************************************************
  439. *                                                                                 *
  440. *                      Max, Min and Positive Difference                         *
  441. *                                                                                 *
  442. *     fdim        Determines the 'positive difference' between its arguments:     *
  443. *                { x - y, if x > y }, { +0, if x <= y }.  If one argument is        *
  444. *                  NaN, then fdim returns that NaN.  if both arguments are NaNs,     *
  445. *                 then fdim returns the first argument.                            *
  446. *                                                                                 *
  447. *     fmax        Returns the maximum of the two arguments.  Corresponds to the    *
  448. *                max function in FORTRAN.  NaN arguments are treated as missing     *
  449. *                data.  If one argument is NaN and the other is a number, then     *
  450. *                the number is returned.  If both are NaNs then the first         *
  451. *                argument is returned.                                             *
  452. *                                                                                 *
  453. *     fmin        Returns the minimum of the two arguments.  Corresponds to the    *
  454. *                min function in FORTRAN.  NaN arguments are treated as missing     *
  455. *                data.  If one argument is NaN and the other is a number, then     *
  456. *                the number is returned.  If both are NaNs then the first         *
  457. *                argument is returned.                                            *
  458. *                                                                                 *
  459. ********************************************************************************/
  460. EXTERN_API_C( double_t ) fdim(double_t x, double_t y);
  461.  
  462. EXTERN_API_C( double_t ) fmax(double_t x, double_t y);
  463.  
  464. EXTERN_API_C( double_t ) fmin(double_t x, double_t y);
  465.  
  466.  
  467.  
  468. /*******************************************************************************
  469. *                                Constants                                     *
  470. *******************************************************************************/
  471. extern const double_t pi;
  472.  
  473.  
  474. /********************************************************************************
  475. *                                                                                 *
  476. *                              Non NCEG extensions                                *
  477. *                                                                                 *
  478. ********************************************************************************/
  479. #if TARGET_OS_MAC
  480. #ifndef __NOEXTENSIONS__
  481. /********************************************************************************
  482. *                                                                                 *
  483. *                              Financial functions                              *
  484. *                                                                                 *
  485. *     compound        Computes the compound interest factor "(1 + rate)^periods"    *
  486. *                      more accurately than the straightforward computation with     *
  487. *                    the Power function.  This is SANE's compound function.      *
  488. *                                                                                 *
  489. *     annuity            Computes the present value factor for an annuity             *
  490. *                      "(1 - (1 + rate)^(-periods)) /rate" more accurately than    *
  491. *                    the straightforward computation with the Power function.     *
  492. *                    This is SANE's annuity function.                              *
  493. *                                                                                 *
  494. ********************************************************************************/
  495. EXTERN_API_C( double_t ) compound(double_t rate, double_t periods);
  496.  
  497. EXTERN_API_C( double_t ) annuity(double_t rate, double_t periods);
  498.  
  499.  
  500.  
  501. /********************************************************************************
  502. *                                                                                 *
  503. *                              Random function                                  *
  504. *                                                                                 *
  505. *     randomx            A pseudorandom number generator.  It uses the iteration:    *
  506. *                                (75*x)mod(2^31-1)                                *
  507. *                                                                                 *
  508. ********************************************************************************/
  509. EXTERN_API_C( double_t ) randomx(double_t *x);
  510.  
  511.  
  512.  
  513. /*******************************************************************************
  514. *                              Relational operator                             *
  515. *******************************************************************************/
  516. /*      relational operator      */
  517. typedef short                             relop;
  518.  
  519. enum {
  520.     GREATERTHAN                    = 0,
  521.     LESSTHAN                    = 1,
  522.     EQUALTO                        = 2,
  523.     UNORDERED                    = 3
  524. };
  525.  
  526. EXTERN_API_C( relop ) relation(double_t x, double_t y);
  527.  
  528.  
  529.  
  530. /********************************************************************************
  531. *                                                                                 *
  532. *                         Binary to decimal conversions                         *
  533. *                                                                                 *
  534. *     SIGDIGLEN    Significant decimal digits.                                        *
  535. *                                                                                 *
  536. *     decimal        A record which provides an intermediate unpacked form for        *
  537. *                programmers who wish to do their own parsing of numeric input     *
  538. *                or formatting of numeric output.                                  *
  539. *                                                                                 *
  540. *     decform        Controls each conversion to a decimal string.  The style field     *
  541. *                is either FLOATDECIMAL or FIXEDDECIMAL. If FLOATDECIMAL, the     *
  542. *                value of the field digits is the number of significant digits.  *
  543. *                  If FIXEDDECIMAL value of the field digits is the number of        *
  544. *                digits to the right of the decimal point.                         *
  545. *                                                                                 *
  546. *     num2dec        Converts a double_t to a decimal record    using a decform.        *
  547. *     dec2num        Converts a decimal record d to a double_t value.                *
  548. *     dec2str        Converts a decform and decimal to a string using a decform.        *
  549. *     str2dec        Converts a string to a decimal struct.                            *
  550. *     dec2d        Similar to dec2num except a double is returned (68k only).        *
  551. *     dec2f        Similar to dec2num except a float is returned.                    *
  552. *     dec2s        Similar to dec2num except a short is returned.                    *
  553. *     dec2l        Similar to dec2num except a long is returned.                     *
  554. *                                                                                 *
  555. ********************************************************************************/
  556. #if    TARGET_CPU_PPC
  557.     #define SIGDIGLEN      36              
  558. #elif TARGET_CPU_68K
  559.     #define SIGDIGLEN      20
  560. #endif
  561. #define      DECSTROUTLEN   80               /* max length for dec2str output */
  562. #define      FLOATDECIMAL   ((char)(0))
  563. #define      FIXEDDECIMAL   ((char)(1))
  564.  
  565.  
  566. struct decimal {
  567.     char                             sgn;                        /* sign 0 for +, 1 for - */
  568.     char                             unused;
  569.     short                             exp;                        /* decimal exponent */
  570.     struct {
  571.         unsigned char                     length;
  572.         unsigned char                     text[SIGDIGLEN];        /* significant digits */
  573.         unsigned char                     unused;
  574.     }                                 sig;
  575. };
  576. typedef struct decimal decimal;
  577.  
  578. struct decform {
  579.     char                             style;                        /*  FLOATDECIMAL or FIXEDDECIMAL */
  580.     char                             unused;
  581.     short                             digits;
  582. };
  583. typedef struct decform decform;
  584.  
  585. EXTERN_API_C( void ) num2dec(const decform *f, double_t x, decimal *d);
  586.  
  587. EXTERN_API_C( double_t ) dec2num(const decimal *d);
  588.  
  589. EXTERN_API_C( void ) dec2str(const decform *f, const decimal *d, char *s);
  590.  
  591. EXTERN_API_C( void ) str2dec(const char *s, short *ix, decimal *d, short *vp);
  592.  
  593. #if TARGET_CPU_68K
  594. EXTERN_API_C( double ) dec2d(const decimal *d);
  595.  
  596. #endif  /* TARGET_CPU_68K */
  597.  
  598. EXTERN_API_C( float ) dec2f(const decimal *d);
  599.  
  600. EXTERN_API_C( short ) dec2s(const decimal *d);
  601.  
  602. EXTERN_API_C( long ) dec2l(const decimal *d);
  603.  
  604.  
  605.  
  606.  
  607. /********************************************************************************
  608. *                                                                                 *
  609. *                         68k-only Transfer Function Prototypes                 *
  610. *                                                                                 *
  611. ********************************************************************************/
  612. #if TARGET_CPU_68K
  613. #if TARGET_RT_MAC_68881
  614. EXTERN_API_C( void ) x96tox80(const extended96 *x, extended80 *x80);
  615.  
  616. EXTERN_API_C( void ) x80tox96(const extended80 *x80, extended96 *x);
  617.  
  618. #else
  619. EXTERN_API_C( void ) x96tox80(const extended96 *x96, extended80 *x);
  620.  
  621. EXTERN_API_C( void ) x80tox96(const extended80 *x, extended96 *x96);
  622.  
  623. #endif  /* TARGET_RT_MAC_68881 */
  624.  
  625. #endif  /* TARGET_CPU_68K */
  626.  
  627. #endif  /*  ! defined(__NOEXTENSIONS__)  */
  628.  
  629. #endif  /* TARGET_OS_MAC */
  630.  
  631. /********************************************************************************
  632. *                                                                                 *
  633. *                         PowerPC-only Function Prototypes                         *
  634. *                                                                                 *
  635. ********************************************************************************/
  636.  
  637. #if TARGET_CPU_PPC
  638. EXTERN_API_C( long double ) cosl(long double x);
  639.  
  640. EXTERN_API_C( long double ) sinl(long double x);
  641.  
  642. EXTERN_API_C( long double ) tanl(long double x);
  643.  
  644. EXTERN_API_C( long double ) acosl(long double x);
  645.  
  646. EXTERN_API_C( long double ) asinl(long double x);
  647.  
  648. EXTERN_API_C( long double ) atanl(long double x);
  649.  
  650. EXTERN_API_C( long double ) atan2l(long double y, long double x);
  651.  
  652. EXTERN_API_C( long double ) coshl(long double x);
  653.  
  654. EXTERN_API_C( long double ) sinhl(long double x);
  655.  
  656. EXTERN_API_C( long double ) tanhl(long double x);
  657.  
  658. EXTERN_API_C( long double ) acoshl(long double x);
  659.  
  660. EXTERN_API_C( long double ) asinhl(long double x);
  661.  
  662. EXTERN_API_C( long double ) atanhl(long double x);
  663.  
  664. EXTERN_API_C( long double ) expl(long double x);
  665.  
  666. EXTERN_API_C( long double ) expm1l(long double x);
  667.  
  668. EXTERN_API_C( long double ) exp2l(long double x);
  669.  
  670. EXTERN_API_C( long double ) frexpl(long double x, int *exponent);
  671.  
  672. EXTERN_API_C( long double ) ldexpl(long double x, int n);
  673.  
  674. EXTERN_API_C( long double ) logl(long double x);
  675.  
  676. EXTERN_API_C( long double ) log1pl(long double x);
  677.  
  678. EXTERN_API_C( long double ) log10l(long double x);
  679.  
  680. EXTERN_API_C( long double ) log2l(long double x);
  681.  
  682. EXTERN_API_C( long double ) logbl(long double x);
  683.  
  684. EXTERN_API_C( long double ) scalbl(long double x, long n);
  685.  
  686. EXTERN_API_C( long double ) fabsl(long double x);
  687.  
  688. EXTERN_API_C( long double ) hypotl(long double x, long double y);
  689.  
  690. EXTERN_API_C( long double ) powl(long double x, long double y);
  691.  
  692. EXTERN_API_C( long double ) sqrtl(long double x);
  693.  
  694. EXTERN_API_C( long double ) erfl(long double x);
  695.  
  696. EXTERN_API_C( long double ) erfcl(long double x);
  697.  
  698. EXTERN_API_C( long double ) gammal(long double x);
  699.  
  700. EXTERN_API_C( long double ) lgammal(long double x);
  701.  
  702. EXTERN_API_C( long double ) ceill(long double x);
  703.  
  704. EXTERN_API_C( long double ) floorl(long double x);
  705.  
  706. EXTERN_API_C( long double ) rintl(long double x);
  707.  
  708. EXTERN_API_C( long double ) nearbyintl(long double x);
  709.  
  710. EXTERN_API_C( long ) rinttoll(long double x);
  711.  
  712. EXTERN_API_C( long double ) roundl(long double x);
  713.  
  714. EXTERN_API_C( long ) roundtoll(long double round);
  715.  
  716. EXTERN_API_C( long double ) truncl(long double x);
  717.  
  718. EXTERN_API_C( long double ) remainderl(long double x, long double y);
  719.  
  720. EXTERN_API_C( long double ) remquol(long double x, long double y, int *quo);
  721.  
  722. EXTERN_API_C( long double ) copysignl(long double x, long double y);
  723.  
  724. EXTERN_API_C( long double ) fdiml(long double x, long double y);
  725.  
  726. EXTERN_API_C( long double ) fmaxl(long double x, long double y);
  727.  
  728. EXTERN_API_C( long double ) fminl(long double x, long double y);
  729.  
  730.  
  731. #ifndef __NOEXTENSIONS__
  732. EXTERN_API_C( relop ) relationl(long double x, long double y);
  733.  
  734. EXTERN_API_C( void ) num2decl(const decform *f, long double x, decimal *d);
  735.  
  736. EXTERN_API_C( long double ) dec2numl(const decimal *d);
  737.  
  738. #if TARGET_OS_MAC
  739. /*    
  740.     MathLib v2 has two new transfer functions: x80tod and dtox80.  They can 
  741.     be used to directly transform 68k 80-bit extended data types to double
  742.     and back for PowerPC based machines without using the functions
  743.     x80told or ldtox80.  Double rounding may occur. 
  744. */
  745. EXTERN_API_C( void ) x80told(const extended80 *x80, long double *x);
  746.  
  747. EXTERN_API_C( void ) ldtox80(const long double *x, extended80 *x80);
  748.  
  749. EXTERN_API_C( double ) x80tod(const extended80 *x80);
  750.  
  751. EXTERN_API_C( void ) dtox80(const double *x, extended80 *x80);
  752.  
  753. #endif  /* TARGET_OS_MAC */
  754.  
  755. #endif  /*  ! defined(__NOEXTENSIONS__)  */
  756.  
  757. #endif  /* TARGET_CPU_PPC */
  758.  
  759.  
  760. #if PRAGMA_STRUCT_ALIGN
  761.     #pragma options align=reset
  762. #elif PRAGMA_STRUCT_PACKPUSH
  763.     #pragma pack(pop)
  764. #elif PRAGMA_STRUCT_PACK
  765.     #pragma pack()
  766. #endif
  767.  
  768. #ifdef PRAGMA_IMPORT_OFF
  769. #pragma import off
  770. #elif PRAGMA_IMPORT
  771. #pragma import reset
  772. #endif
  773.  
  774. #ifdef __cplusplus
  775. }
  776. #endif
  777.  
  778. #endif /* __FP__ */
  779.  
  780.